package com.zmj.controller;

import com.zmj.dto.TableData;
import com.zmj.entity.ScheduleJob;
import com.zmj.service.ScheduleService;
import com.zmj.utils.Response;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
public class ScheduleController {
    @Resource
    private ScheduleService scheduleJobService;


    @RequestMapping("/schedule/job/list")
    public TableData scheduleList(String search,String order,int limit ,int offset){

        return  scheduleJobService.findScheduleJob(search,order,limit,offset);
    }

    @RequestMapping("/schedule/job/info/{scheduleJobId}")
    public Response scheduleJobInfo(@PathVariable long scheduleJobId){

        return  scheduleJobService.findScheduleJobById(scheduleJobId);
    }

    @RequestMapping("/schedule/job/save")
    public   Response  saveScheduleJob(@RequestBody ScheduleJob scheduleJob){
        scheduleJob.setCreateTime(new Date());
        scheduleJob.setStatus((byte)0);

        return  scheduleJobService.insertScheduleJob(scheduleJob);
    }

    @RequestMapping("/schedule/job/update")
    public   Response  updateScheduleJob(@RequestBody ScheduleJob scheduleJob){
        return  scheduleJobService.updateScheduleJob(scheduleJob);
    }

    @RequestMapping("/schedule/job/del")
    public  Response  delete(@RequestBody List<Long> ids){

        return  scheduleJobService.deleteByIds(ids);
    }


    @RequestMapping("/schedule/job/resume")
    public   Response resumeTask(@RequestBody List<Long> ids){
        return  scheduleJobService.resumeTask(ids);
    }

    @RequestMapping("/schedule/job/pause")
    public   Response  pauseTask(@RequestBody List<Long> ids){
        return  scheduleJobService.pauseTask(ids);
    }

    @RequestMapping("/schedule/job/run")
    public   Response runOnce(@RequestBody List<Long> ids){
        return  scheduleJobService.runOnceTask(ids);
    }
}
